package org.chnxi.study.serialize.jackson;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;

public class JacksonTest {

    public static void main(String[] args) throws JsonProcessingException {
        HeadTeacher ht = new HeadTeacher();
        EnglishTeacher et = new EnglishTeacher();
        ArrayList<Teacher> teachers = new ArrayList<>();
        teachers.add(ht);
        teachers.add(et);

        Student s = new Student();
        s.setName("张三");
        s.setTeachers(teachers);

        ArrayList<Student> studentes = new ArrayList<Student>();
        studentes.add(s);
        et.setStudentes(studentes);

        EnglishBook eb = new EnglishBook();
        ChineseBook cb = new ChineseBook();
        ArrayList<Book> books = new ArrayList<>();
        books.add(eb);
        books.add(cb);
        s.setBooks(books);

        String str = JSONUtil.object2String(s);
        System.out.println(str);


        Student s2 = JSONUtil.string2Object(str , Student.class);
        System.out.println(s2);

    }

}
